var textArray = new Array()

module.exports = function deparser(htmlDom) {
  // htmlDom.getElementsByTagName('div')
  let parts = htmlDom.getElementsByClassName('part')
  for (var i = 0; i < parts.length; i++) {
    let divDom = parts[i]
    textArray.push('```' + divDom.dataset.name)
    parsePart(divDom)
    textArray.push('```')
  }
  textArray.forEach((line) => {
    console.log(line)
  })
}

function parsePart(partDom) {
  let doms = partDom.children
  for (var i = 0; i < doms.length; i++) {
    if (doms[i].tagName == 'P') {
      textArray.push('#' + doms[i].textContent)
      continue
    }
    if (doms[i].tagName == 'DIV') {
      parseLine(doms[i])
    }
  }
  console.log(partDom.children)
}

function parseLine(lineDom) {
  let spans = lineDom.children
  let line = ''
  for (var i = 0; i < spans.length; i++) {
    let dom = spans[i]
    line += dom.textContent
    if (dom.className == "chord") {
      line += '[' + dom.dataset.chord + ']'
    }
  }
  textArray.push(line)
}